home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / RTANKSRC.ZIP / CALLASM.C < prev    next >
C/C++ Source or Header  |  1995-03-07  |  16KB  |  572 lines

  1. void Plant_a_forest(void);
  2. void PlantTree(int x, int y);
  3. void inc_manual_view(int x, int y);
  4. void view_manual(void);
  5. void init_manual_track(void);
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <conio.h>
  10.  
  11. #include "dtypes.h"
  12. #include "tiles.h"
  13. #include "host.h"
  14. #include "newload.h"
  15. #include "callasm.h"
  16.  
  17. #define TANKSTART TANK1D8A
  18. #define BWALL     1
  19. #define BTANK     2
  20.  
  21. extern BOOL update_scr;
  22.  
  23. int empty;
  24.  
  25. int top1, left1;
  26.  
  27. int rx1, rx2, ry1, ry2, top, left;
  28.  
  29. /*<f>----------------------------------------
  30.  * FUNCTION: <s> void follow_tank(p_TANK t)
  31.  * PURPOSE : track the motion of a tank T
  32.  *         :
  33.  * CREATION: 01/06/1989 12:18:58
  34.  */
  35. void follow_tank(p_TANK t)
  36. {
  37.       monitor_tank(t);
  38. } /* void follow_tank(p_TANK t) */
  39.  
  40. /*<f>----------------------------------------
  41.  * FUNCTION: <s> void v_startup_playfield(int t)
  42.  * PURPOSE : Set up graphics table and go to CGA mode
  43.  *         :
  44.  * CREATION: 01/06/1989 12:11:27
  45.  */
  46. void v_startup_playfield(int t)
  47. {
  48.    gotocga();
  49.    inittables();
  50.  
  51.    setphyXY(0,0);
  52.    setwindXY(WINDX,WINDY);
  53.  
  54.    initmap(t);
  55.  
  56.    gotoxy(1,21); printf("TANK #         NAME ");
  57.    gotoxy(1,22); printf("DAMAGE         HITS ");
  58.  
  59.    gotoxy(1,24); printf("Press 0-9, SPACE to view, ESC to END");
  60.  
  61.    capturescr();
  62.  
  63. } /* void v_startup_playfield(int t) */
  64.  
  65. /*-------------------------------------
  66.  * Function : void monitor_tank(p_TANK t)
  67.  * Purpose  : Monitor the actions of tank pointed to by T
  68.  * Date     : 12/18/1988 14:48:45
  69.  */
  70. void monitor_tank(p_TANK t)
  71. {
  72.     check_tank_position(t);
  73.     setlogXY(left,top);
  74.     regenscr();
  75.     refreshscr();
  76. } /* void monitor_tank(p_TANK t) */
  77.  
  78.  /*<f>----------------------------------------
  79.   * FUNCTION: <s> void RectMap(int x1, int y1, int x2, int y2, int b)
  80.   * PURPOSE : Fill map from (x1,y1) to (x2,y2) with tile B
  81.   *         :
  82.   * CREATION: 12/13/1988 08:14:15
  83.   */
  84. void RectMap(int x1, int y1, int x2, int y2, int b)
  85. {
  86. int x,y;
  87.  
  88.    for (y=y1; y<=y2; y++)
  89.       for (x=x1; x<=x2; x++)
  90.          setmapXY(x,y,b);
  91.  
  92. } /* void RectMap(int x1, int y1, int x2, int y2, int b) */
  93.  
  94. /*<f>----------------------------------------
  95.  * FUNCTION: <s> void vMapLine(int x, int y1, int y2, int b)
  96.  * PURPOSE : Draw a vertical line from (x,y1) to (x,y2) with tile B
  97.  *         :
  98.  * CREATION: 12/13/1988 08:22:43
  99.  */
  100. void vMapLine(int x, int y1, int y2, int b)
  101. {
  102. int y;
  103.    for (y=y1; y<=y2; y++)
  104.       setmapXY(x,y,b);
  105. } /* void vMapLine(int x, int y1, int y2, int b) */
  106.  
  107. /*<f>----------------------------------------
  108.  * FUNCTION: <s> void hMapLine(int y, int x1, int x2, int b)
  109.  * PURPOSE : Draw a horizontal line from (x1,y) to (x2,y) with tile B
  110.  *         :
  111.  * CREATION: 12/13/1988 12:11:02
  112.  */
  113. void hMapLine(int y, int x1, int x2, int b)
  114. {
  115. int x;
  116.    for (x=x1; x<=x2; x++)
  117.       setmapXY(x,y,b);
  118. } /* void hMapLine(int y, int x1, int x2, int b) */
  119.  
  120. /*<f>----------------------------------------
  121.  * FUNCTION: <s> void RandRectMap(int x1, int y1, int x2, int y2, int B)
  122.  * PURPOSE : Create a fuzzy rectangle within (x1,y1) - (x2,y2) with tile B
  123.  *         :
  124.  * CREATION: 12/13/1988 14:07:55
  125.  */
  126. void RandRectMap(int x1, int y1, int x2, int y2, int b)
  127. {
  128. int xr, yr,a, x,y;
  129.  
  130.    xr=abs(x2-x1);
  131.    yr=abs(y2-y1);
  132.  
  133.    for (a=0; a<(xr*yr) >> 1; a++) {
  134.       x=x1+(rand() % xr);
  135.       y=y1+(rand() % yr);
  136.       setmapXY(x,y,b);
  137.    }
  138. } /* void RandRectMap(int x1, int y1, int x2, int y2, int b) */
  139.  
  140. /*-------------------------------------
  141.  * Function : void initmap(int t)
  142.  * Purpose  : Initilize map to playfield data
  143.  * Date     : 12/18/1988 14:36:31
  144.  */
  145. void initmap(int t)
  146. {
  147.    RectMap(MINPX,MINPY,MAXPX,MAXPY,TGREEN);
  148.    RandRectMap(MINPX,MINPY,MAXPX,MAXPY,GRASS);
  149.  
  150.    hMapLine(MINPY,MINPX,MAXPX,TRED);
  151.    hMapLine(MAXPY,MINPX,MAXPX,TRED);
  152.    vMapLine(MINPX,MINPY,MAXPY,TRED);
  153.    vMapLine(MAXPX,MINPY,MAXPY,TRED);
  154.  
  155.    if (t!=TGRASS) {
  156.       RandRectMap(10,4,44,31,SWAMP);
  157.       RandRectMap(80,27,110,70,SWAMP);
  158.    }
  159.  
  160.    if (t==TWOODS)
  161.        Plant_a_forest();
  162.  
  163.    if (t==TVILLAGE) {
  164.  
  165.       hMapLine(40,10,35,BRICK);
  166.       vMapLine(22,40,49,BRICK);
  167.       hMapLine(55,20,45,BRICK);
  168.       vMapLine(30,46,55,BRICK);
  169.  
  170.       RectMap(16,10,27,19,BRICK);
  171.       RectMap(32,21,38,25,BRICK);
  172.       vMapLine(90,55,65,BRICK);
  173.       hMapLine(55,90,105,BRICK);
  174.    }
  175.  
  176. } /* void initmap(int t) */
  177.  
  178. /*-------------------------------------
  179.  * Function : void PlantTree(int x, int y)
  180.  * Purpose  : Plant a large tree with (x,y) at top-left
  181.  * Date     : 02/09/1989 19:30:38
  182.  */
  183. void PlantTree(int x, int y)
  184. {
  185.    setmapXY(x  ,y  ,TREE11);
  186.    setmapXY(x+1,y  ,TREE12);
  187.    setmapXY(x+2,y  ,TREE13);
  188.    setmapXY(x  ,y+1,TREE21);
  189.    setmapXY(x+1,y+1,TREE22);
  190.    setmapXY(x+2,y+1,TREE23);
  191.    setmapXY(x  ,y+2,TREE31);
  192.    setmapXY(x+1,y+2,TREE32);
  193.    setmapXY(x+2,y+2,TREE33);
  194. } /* void PlantTree(int x, int y) */
  195.  
  196. /*-------------------------------------
  197.  * Function : void Plant_a_forest(void)
  198.  * Purpose  : Make a scatter of trees
  199.  * Date     : 02/09/1989 19:35:05
  200.  */
  201. void Plant_a_forest(void)
  202. {
  203. int a;
  204.  
  205.     for (a=0; a<40+(rand() % 40); a++)
  206.         PlantTree(1+(rand() % (MAXPX-5)), 1+(rand() % (MAXPY-5)));
  207. } /* void Plant_a_forest(void) */
  208.  
  209.  
  210. /*-------------------------------------
  211.  * Function : void init_tank_image(p_TANK t, int tm)
  212.  * Purpose  : Initilize tank image data to known value
  213.  * Date     : 12/18/1988 14:37:55
  214.  */
  215. void init_tank_image(p_TANK t, int tm)
  216. {
  217. int a;
  218.  
  219.     t->cpoint = 1+rand()%8;
  220.     t->cgpoint= 1+rand()%8;
  221.  
  222.     t->px    =rand() % MAXPX;
  223.     t->py    =rand() % MAXPY;
  224.  
  225.     set_move_range(t);
  226.  
  227.     if (tm==0) {
  228.        init_view(&t->pic[0],TANK1D1A, TANK1D1B, TANK1D1C, TANK1D1D);
  229.        init_view(&t->pic[2],TANK1D3A, TANK1D3B, TANK1D3C, TANK1D3D);
  230.        init_view(&t->pic[1],TANK1D2A, TANK1D2B, TANK1D2C, TANK1D2D);
  231.        init_view(&t->pic[3],TANK1D4A, TANK1D4B, TANK1D4C, TANK1D4D);
  232.        init_view(&t->pic[5],TANK1D6A, TANK1D6B, TANK1D6C, TANK1D6D);
  233.        init_view(&t->pic[4],TANK1D5A, TANK1D5B, TANK1D5C, TANK1D5D);
  234.        init_view(&t->pic[6],TANK1D7A, TANK1D7B, TANK1D7C, TANK1D7D);
  235.        init_view(&t->pic[7],TANK1D8A, TANK1D8B, TANK1D8C, TANK1D8D);
  236.     } else if (tm==1) {
  237.        init_view(&t->pic[0],TANK21A, TANK21B, TANK21C, TANK21D);
  238.        init_view(&t->pic[2],TANK23A, TANK23B, TANK23C, TANK23D);
  239.        init_view(&t->pic[4],TANK25A, TANK25B, TANK25C, TANK25D);
  240.        init_view(&t->pic[6],TANK27A, TANK27B, TANK27C, TANK27D);
  241.        init_view(&t->pic[1],TANK22A, TANK22B, TANK22C, TANK22D);
  242.        init_view(&t->pic[3],TANK24A, TANK24B, TANK24C, TANK24D);
  243.        init_view(&t->pic[5],TANK26A, TANK26B, TANK26C, TANK26D);
  244.        init_view(&t->pic[7],TANK28A, TANK28B, TANK28C, TANK28D);
  245.     } else {
  246.        init_view(&t->pic[0],TANK31A, TANK31B, TANK31C, TANK31D);
  247.        init_view(&t->pic[2],TANK33A, TANK33B, TANK33C, TANK33D);
  248.        init_view(&t->pic[4],TANK35A, TANK35B, TANK35C, TANK35D);
  249.        init_view(&t->pic[6],TANK37A, TANK37B, TANK37C, TANK37D);
  250.        init_view(&t->pic[1],TANK32A, TANK32B, TANK32C, TANK32D);
  251.        init_view(&t->pic[3],TANK34A, TANK34B, TANK34C, TANK34D);
  252.        init_view(&t->pic[5],TANK36A, TANK36B, TANK36C, TANK36D);
  253.        init_view(&t->pic[7],TANK38A, TANK38B, TANK38C, TANK38D);
  254.     }
  255.  
  256.     save_under_tank(t);
  257.  
  258. } /* void init_tank_image(p_TANK t, int tm) */
  259.  
  260. /*-------------------------------------
  261.  * Function : void init_view(p_TANKTILE t, int ta, int tb, int tc, int td)
  262.  * Purpose  : Initilize each view of tank during rotation
  263.  * Date     : 12/18/1988 14:58:45
  264.  */
  265. void init_view(p_TANKTILE t, int ta, int tb, int tc, int td)
  266. {
  267.    t->image[0]=ta;
  268.    t->image[1]=tb;
  269.    t->image[2]=tc;
  270.    t->image[3]=td;
  271. } /* void init_view(p_TANKTILE t, int ta, int tb, int tc, int td) */
  272.  
  273. /*-------------------------------------
  274.  * Function : void save_under_tank(p_TANK t)
  275.  * Purpose  : Saves image under tank image
  276.  * Date     : 12/18/1988 14:42:21
  277.  */
  278. void save_under_tank(p_TANK t)
  279. {
  280.    t->save.image[0]=getmapXY(t->px  ,t->py  );
  281.    t->save.image[1]=getmapXY(t->px+1,t->py  );
  282.    t->save.image[2]=getmapXY(t->px  ,t->py+1);
  283.    t->save.image[3]=getmapXY(t->px+1,t->py+1);
  284. } /* void save_under_tank(p_TANK t) */
  285.  
  286. /*-------------------------------------
  287.  * Function : void restore_under_tank(p_TANK t)
  288.  * Purpose  : Restore image under tank tiles
  289.  * Date     : 12/18/1988 15:04:20
  290.  */
  291. void restore_under_tank(p_TANK t)
  292. {
  293.    setmapXY(t->px,  t->py  ,t->save.image[0]);
  294.    setmapXY(t->px+1,t->py  ,t->save.image[1]);
  295.    setmapXY(t->px,  t->py+1,t->save.image[2]);
  296.    setmapXY(t->px+1,t->py+1,t->save.image[3]);
  297. } /* void restore_under_tank(p_TANK t) */
  298.  
  299. /*-------------------------------------
  300.  * Function : void display_tank(p_TANK t)
  301.  * Purpose  : Draws tank onto map file
  302.  * Date     : 12/18/1988 15:01:41
  303.  */
  304. void display_tank(p_TANK t)
  305. {
  306.    save_under_tank(t);
  307.    if (!t->boom) {
  308.       setmapXY(t->px,  t->py  ,t->pic[t->cgpoint-1].image[0]);
  309.       setmapXY(t->px+1,t->py  ,t->pic[t->cgpoint-1].image[1]);
  310.       setmapXY(t->px,  t->py+1,t->pic[t->cgpoint-1].image[2]);
  311.       setmapXY(t->px+1,t->py+1,t->pic[t->cgpoint-1].image[3]);
  312.    } else {
  313.       if (t->jiggle) {
  314.          setmapXY(t->px  ,t->py  ,BOOM1);
  315.          setmapXY(t->px+1,t->py  ,BOOM2);
  316.          setmapXY(t->px  ,t->py+1,BOOM3);
  317.          setmapXY(t->px+1,t->py+1,BOOM4);
  318.       } else {
  319.          setmapXY(t->px  ,t->py  ,BOOMA1);
  320.          setmapXY(t->px+1,t->py  ,BOOMA2);
  321.          setmapXY(t->px  ,t->py+1,BOOMA3);
  322.          setmapXY(t->px+1,t->py+1,BOOMA4);
  323.       }
  324.  
  325.       t->jiggle=~t->jiggle;
  326.       update_scr=TRUE;
  327.  
  328.       t->bwait--;
  329.       if (t->bwait<1) t->boom=FALSE;
  330.    }
  331.  
  332. } /* void display_tank(p_TANK t) */
  333.  
  334. /*-------------------------------------
  335.  * Function : BOOL clear(int x, int y)
  336.  * Purpose  : Is it clear at (x,y)
  337.  * Date     : 12/19/1988 23:18:13
  338.  */
  339. BOOL clear(int x, int y)
  340. {
  341. int a;
  342. int t;
  343.  
  344.     a=getmapXY(x,y);
  345.     t=0;
  346.  
  347.     if ((a>=BRICK && a< TANKSTART) || a==TRED)
  348.         empty=t=BWALL;
  349.     if (a>=TANKSTART)
  350.         empty=t=BTANK;
  351.  
  352.     return (t>0) ? FALSE : TRUE;
  353. } /* BOOL clear(int x, int y) */
  354.  
  355. /*-------------------------------------
  356.  * Function : BOOL check_above(p_TANK t)
  357.  * Purpose  : Make sure clear to move above
  358.  * Date     : 12/19/1988 23:15:44
  359.  */
  360. BOOL check_above(p_TANK t)
  361. {
  362.    return (clear(t->px,t->py-1) && clear(t->px+1,t->py-1)) ? TRUE : FALSE;
  363.  
  364. } /* BOOL check_above(p_TANK t) */
  365.  
  366. /*-------------------------------------
  367.  * Function : BOOL check_below(p_TANK t)
  368.  * Purpose  : Make sure clear below to move
  369.  * Date     : 12/19/1988 23:19:19
  370.  */
  371. BOOL check_below(p_TANK t)
  372. {
  373.    return (clear(t->px,t->py+2) && clear(t->px+1, t->py+2)) ? TRUE : FALSE;
  374.  
  375. } /* BOOL check_below(p_TANK t) */
  376.  
  377. /*-------------------------------------
  378.  * Function : BOOL check_left(p_TANK t)
  379.  * Purpose  : Make sure clear to move left
  380.  * Date     : 12/19/1988 23:20:15
  381.  */
  382. BOOL check_left(p_TANK t)
  383. {
  384.    return (clear(t->px-1,t->py) && clear(t->px-1, t->py+1)) ? TRUE : FALSE;
  385.  
  386. } /* BOOL check_left(p_TANK t) */
  387.  
  388. /*-------------------------------------
  389.  * Function : BOOL check_right(p_TANK t)
  390.  * Purpose  : Make sure clear to move right
  391.  * Date     : 12/19/1988 23:21:04
  392.  */
  393. BOOL check_right(p_TANK t)
  394. {
  395.    return (clear(t->px+2,t->py) && clear(t->px+2,t->py+1)) ? TRUE : FALSE;
  396. } /* BOOL check_right(p_TANK t) */
  397.  
  398. /*-------------------------------------
  399.  * Function : void move_up(p_TANK t)
  400.  * Purpose  : Move tanks current position up one tile
  401.  * Date     : 12/18/1988 15:09:35
  402.  */
  403. void move_up(p_TANK t)
  404. {
  405.    if (t->py>MINPY && check_above(t)) t->py--;
  406. } /* void move_up(p_TANK t) */
  407.  
  408. /*-------------------------------------
  409.  * Function : void move_down(p_TANK t)
  410.  * Purpose  : Move tanks current position down one tile
  411.  * Date     : 12/18/1988 15:10:21
  412.  */
  413. void move_down(p_TANK t)
  414. {
  415.     if (t->py+1<MAXPY && check_below(t)) t->py++;
  416.  
  417. } /* void move_down(p_TANK t) */
  418.  
  419. /*-------------------------------------
  420.  * Function : void move_left(p_TANK t)
  421.  * Purpose  : Move tanks current position left one position
  422.  * Date     : 12/18/1988 15:11:20
  423.  */
  424. void move_left(p_TANK t)
  425. {
  426.    if (t->px>MINPX && check_left(t)) t->px--;
  427. } /* void move_left(p_TANK t) */
  428.  
  429. /*-------------------------------------
  430.  * Function : void move_right(p_TANK t)
  431.  * Purpose  : Move tanks current position right one tile position
  432.  * Date     : 12/18/1988 15:11:57
  433.  */
  434. void move_right(p_TANK t)
  435. {
  436.    if (t->px+1<MAXPX && check_right(t)) t->px++;
  437. } /* void move_right(p_TANK t) */
  438.  
  439. /*-------------------------------------
  440.  * Function : void move_tank(p_TANK t)
  441.  * Purpose  : Move tank T in current direction pointed by t->cpoint
  442.  * Date     : 12/18/1988 15:08:06
  443.  */
  444. void move_tank(p_TANK t)
  445. {
  446. int ox, oy;
  447.  
  448.    ox=t->px;
  449.    oy=t->py;
  450.  
  451.    empty = FALSE;
  452.  
  453.    switch(t->cpoint) {
  454.        case 1 : move_up(t);
  455.                 break;
  456.        case 2 : move_up(t); move_right(t);
  457.                 break;
  458.        case 3 : move_right(t);
  459.                 break;
  460.        case 4 : move_down(t); move_right(t);
  461.                 break;
  462.        case 5 : move_down(t);
  463.                 break;
  464.        case 6 : move_left(t); move_down(t);
  465.                 break;
  466.        case 7 : move_left(t);
  467.                 break;
  468.        case 8 : move_left(t); move_up(t);
  469.                 break;
  470.    }
  471.  
  472.    t->nomove=(ox==t->px && oy==t->py) ? TRUE : FALSE;
  473.  
  474.    t->blockage = empty;
  475.  
  476.    if (!t->nomove) update_scr=TRUE;
  477.  
  478. } /* void move_tank(p_TANK t) */
  479.  
  480. /*-------------------------------------
  481.  * Function : void set_move_range(p_TANK t)
  482.  * Purpose  : Sets window around tank in which tank may move without regen
  483.  * Date     : 12/19/1988 22:59:41
  484.  */
  485. void set_move_range(p_TANK t)
  486. {
  487.  
  488.     left=t->px-HALFWINDX;
  489.     top =t->py-HALFWINDY;
  490.  
  491.     if (left<MINPX) left=MINPX;
  492.     if (top <MINPY) top =MINPY;
  493.     if (left>MAXLX) left=MAXLX;
  494.     if (top >MAXLY) top =MAXLY;
  495.  
  496.     rx1=left+5;
  497.     ry1=top+3;
  498.     rx2=left+WINDX-5;
  499.     ry2=top+WINDY-3;
  500.  
  501. } /* void set_move_range(p_TANK t) */
  502.  
  503. /*-------------------------------------
  504.  * Function : void check_tank_position(p_TANK t)
  505.  * Purpose  : Make sure tank is still within boundries
  506.  * Date     : 12/19/1988 23:04:57
  507.  */
  508. void check_tank_position(p_TANK t)
  509. {
  510.    if (t->px>rx1 && t->px<rx2 && t->py>ry1 && t->py<ry2)
  511.        return;
  512.  
  513.    if (t->px<=rx1) left--;
  514.    if (t->px>=rx2) left++;
  515.    if (t->py<=ry1) top-- ;
  516.    if (t->py>=ry2) top++ ;
  517.  
  518.    if (left<MINPX) left=MINPX;
  519.    if (top <MINPY) top =MINPY;
  520.    if (left>MAXLX) left=MAXLX;
  521.    if (top >MAXLY) top =MAXLY;
  522.  
  523.    rx1=left+5;
  524.    ry1=top+3;
  525.    rx2=left+WINDX-5;
  526.    ry2=top+WINDY-3;
  527.  
  528. } /* void check_tank_position(p_TANK t) */
  529.  
  530. /*<f>----------------------------------------
  531.  * FUNCTION: <s> void init_manual_track(void)
  532.  * PURPOSE :
  533.  *         : Initilize top, left pointers for manual motion
  534.  * CREATION: 01/19/1989 14:07:43
  535.  */
  536. void init_manual_track(void)
  537. {
  538.    top1=top;
  539.    left1=left;
  540. } /* void init_manual_track(void) */
  541.  
  542. /*<f>----------------------------------------
  543.  * FUNCTION: <s> void view_manual(void)
  544.  * PURPOSE : Look at screen from manual view
  545.  *         :
  546.  * CREATION: 01/19/1989 14:09:58
  547.  */
  548. void view_manual(void)
  549. {
  550.     setlogXY(left1,top1);
  551.     regenscr();
  552.     refreshscr();
  553. } /* void view_manual(void) */
  554.  
  555. /*<f>----------------------------------------
  556.  * FUNCTION: <s> void inc_manual_view(int x, int y)
  557.  * PURPOSE : Move manual view by (x,y)
  558.  *         :
  559.  * CREATION: 01/19/1989 14:11:00
  560.  */
  561. void inc_manual_view(int x, int y)
  562. {
  563.    top1+=y;
  564.    left1+=x;
  565.  
  566.    if (left1<MINPX) left1=MINPX;
  567.    if (top1 <MINPY) top1 =MINPY;
  568.    if (left1>MAXLX) left1=MAXLX;
  569.    if (top1 >MAXLY) top1 =MAXLY;
  570.  
  571. } /* void inc_manual_view(int x, int y) */
  572.